/*
  码盘解析任务

  处理码盘测量的实际距禄

  将需要的数据共享给其他的线程

*/
#include "action_task.h"
#include "Action.h"
#include "user_task.h"


#ifdef DEBUG

Action_POS_t pos;
#else

static Action_POS pos;

#endif

void Task_action(void *argument)
{
   (void)argument;
//    osDelay(TASK_INIT_DELAY_ACTION); 
   
   const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_ACTION;
   

   ACTIONRECV_Init(&pos);

   
   uint32_t tick = osKernelGetTickCount(); /* 获取当前控制任务运行频率的tick*/

   while (1)
   {
#ifdef DEBUG
    /* 记录任务使用的的栈空闄*/
    task_runtime.stack_water_mark.action =
        osThreadGetStackSpace(osThreadGetId());
#endif
	   	ACTION_StartReceiving();
		 
		  ACTION_DataRefresh(&pos); 

      if(ACTION_WaitDmaCplt()){
         ACTION_Parse(&pos);	
      }
       else{
         Action_HandleOffline(&pos);
       }
      //将解算后的码盘位置值放入消息队列供其他任务使用
      osMessageQueueReset(task_runtime.msgq.cmd.raw.ops_9pos);
      osMessageQueuePut(task_runtime.msgq.cmd.raw.ops_9pos,(&pos),0,0);
		  
			 
    tick += delay_tick; /* 计算下一个唤醒时刻*/
//		osDelayUntil(tick);
   }
}

